package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        LineChart lineChart=findViewById(R.id.lineChart);
        float[]f1={2.0f,90.f,3.0f,4.0f,7.0f,3.0f,5.0f,1.0f,7.0f,};
        float[]f2={3.0f,10.f,4.0f,1.0f,5.0f,3.0f,9.0f,2.0f,6.0f,};

        List<ILineDataSet> s = new ArrayList<>();
        s.add(getDataSet(f1,"demo1"));
        LineDataSet demo1 =getDataSet(f1,"demo1");
        demo1.setColor(Color.parseColor("#deab8a" ));
        demo1.setLineWidth(1.6f);
        demo1.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
        s.add(demo1);

        LineDataSet demo2 =getDataSet(f2,"demo2");
        demo2.setColor(Color.parseColor("#deab8a" ));
        demo2.setLineWidth(1.6f);
        demo2.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
        s.add(getDataSet(f2,"demo2"));
        s.add(demo2);

        XAxis xAxis=lineChart.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setDrawAxisLine(true);

        Legend legend=lineChart.getLegend();
        legend.setEnabled(false);
        lineChart.invalidate();


        lineChart.setData(new LineData(s));
        lineChart.invalidate();

    }

    private LineDataSet getDataSet(float[]f,String title){
        List<Entry>data=new ArrayList<>();
        for (int x=0;x<f.length;x++){
            Entry entry=new Entry(x,f[x]);
            data.add(entry);
        }
        return  new LineDataSet(data,title);
    }
}